package org.weso.acota.services;

import java.util.LinkedList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.QueryParam;

import org.weso.acota.services.to.ListProvidersTO;
import org.weso.acota.to.ProviderTO;
import org.weso.acota.to.RequestSuggestionTO;
import org.weso.acota.to.SuggestionTO;

/**
 *
 * @author chema
 */

@Path("/acotaRest")
public class CotaServiceRest {

    private CotaServiceFacade facade;
    private ListProvidersTO providers;
    public CotaServiceRest(){
        this.facade = new CotaServiceFacadeImpl();
        this.providers = new ListProvidersTO(this.facade.providers());
    }
    @GET
    @Path("suggest")
    @ProduceMime({"text/plain", "application/xml", "application/json"})
    public SuggestionTO suggest(@QueryParam("q") String q, @QueryParam("provider") String provider){
    	List<ProviderTO> providers = new LinkedList<ProviderTO>();
    	providers.add(new ProviderTO(provider));
        RequestSuggestionTO request = new RequestSuggestionTO(q,providers);
        return this.facade.suggest(request);

    }
    @GET
    @Path("providers")
    @ProduceMime({"text/plain", "application/xml", "application/json"})
    public ListProvidersTO providers(){
    	return this.providers;
    }
}
